package com.siyao.redvip.ui.adapter;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import com.siyao.redvip.R;
import android.view.ViewGroup;
import android.content.Context;
import android.webkit.WebView.FindListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.siyao.redvip.bean.HDxxBean;
import com.siyao.redvip.bean.HDxxBean;
import com.siyao.redvip.components.view.LoadingDialog;
import com.siyao.redvip.image.ImageLoaderOptions;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

/**
 * 活动信息
 * @author lenovo
 *
 */
public class HdxxAdapter extends BaseAdapter{
	
	 protected Context mContext;
	 protected LoadingDialog pd;
	 protected List<HDxxBean> mDatas;
	 private LayoutInflater mInflater;//加载list_item
	    
	 public HdxxAdapter(Context context) {
	        this.mContext = context;
	        pd = new LoadingDialog(mContext);
	        pd.setCancelable(false);
	        mInflater = LayoutInflater.from(context);
	    }
	 
	 
	public void setmDatas(List<HDxxBean> mDatas) {
		this.mDatas = mDatas;
	}

	@Override
	public int getCount() {
		 if (mDatas == null) {
	            return 0;
	        }
		return mDatas.size();
	}

	@Override
	public Object getItem(int position) {
		return mDatas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position <= 0 ? 0 :position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder=null;
		if(convertView ==null){
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.activity_hdxx_details_item, null);
			
			holder.tvOrganizationsTitle=(TextView)convertView.findViewById(R.id.tv_organizations_title);
			holder.tvOrganizationsPlace=(TextView)convertView.findViewById(R.id.tv_organizations_place);
			holder.tvOrganizationsTime=(TextView)convertView.findViewById(R.id.tv_organizations_time);
			holder.tvOrganizationsMainText=(TextView)convertView.findViewById(R.id.tv_organizations_main_text);
			holder.itemManText = (TextView) convertView.findViewById(R.id.item_man_text);
			holder.itemPhoneText = (TextView) convertView.findViewById(R.id.item_phone_text);
			
			convertView.setTag(holder);			
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		if(mDatas.size()>0){
			HDxxBean data  = mDatas.get(position);
			
			String title="活动信息";
			String date = data.getGet_startdate();
			String content = data.getGet_name();
			String manager=data.getGet_employeename();
			String phone=data.getGet_tel();
			String address=data.getGet_address();
			
			holder.tvOrganizationsTitle.setText(title);
			holder.tvOrganizationsTime.setText(date);
			holder.tvOrganizationsMainText.setText(content);
			holder.itemManText.setText(manager) ;
			holder.itemPhoneText.setText(phone) ;
			holder.tvOrganizationsPlace.setText(address);
		}
		return convertView;
	}
	
	private static class ViewHolder {
		private TextView tvOrganizationsTitle;//标题
		private TextView tvOrganizationsTime;//时间
		private TextView tvOrganizationsMainText;//内容
		private TextView itemManText ;//负责人
		private TextView itemPhoneText;//电话号码
		private TextView tvOrganizationsPlace;//地点
	}
	
	
    public void setDataChanged(List<HDxxBean> mDatas) {
        if (mDatas != null && !mDatas.isEmpty()) {
            this.mDatas = mDatas;
            this.notifyDataSetChanged();
        }
    }

    public void clear() {
        if (mDatas != null && !mDatas.isEmpty()) {
            this.mDatas.clear();
        }
        this.notifyDataSetChanged();
    }
}
